<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <style>
        .layui-form-item .layui-input-inline {
            width: 150px;
        }

        .layui-form-label {
            padding: 9px 5px;
            width: auto;
        }

        .layui-card-body table {
            width: 1000px;
        }

        .layui-table th {
            text-align: center;
            background-color: #FFF;
            height: 30px;
            line-height: 30px;
            font-weight: bold;
        }

        .layui-table td {
            color: #000;
            text-align: center;
        }

        .layui-table td.color_aaa {
            color: #afafaf;
        }
    </style>
</head>

<body>

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title layui_tab_title">
                    <li><a href="{:url('worldcup/index')}">赛事</a></li>
                    <li><a href="{:url('worldcup/point')}">积分</a></li>
                    <li class="layui-this"><a href="{:url('worldcup/rank')}">晋级图</a></li>
                    <li><a href="{:url('WorldCupGuess/index')}">竞猜</a></li>
                    <li><a href="{:url('WorldCupGuess/order')}">竞猜记录</a></li>
                </ul>
            </div>

            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <button class="layui-btn add-rank-match" data-type="add">添加晋级赛</button>
                    </div>
                </div>
            </div>

            <div class="layui-card-body">
                <table class="layui-table" id="matchTable">
                    <tr>
                        <th colspan="6" align="center">
                            1/8决赛
                        </th>
                    </tr>
                    <tr>
                        <th>主队</th>
                        <th>球队图标</th>
                        <th>客队</th>
                        <th>球队图标</th>
                        <th>设置</th>
                    </tr>
                    {volist name="match_rank" id="rank"}



                    {if $rank.rank_type == 1}
                    <tr>
                        <td>
                            {$rank.home}</td>
                        <td>
                            {notempty name="$rank.home_logo"}
                            <img src="{$rank.home_logo}" height="25">
                            {/notempty}

                        </td>
                        <td>
                            {$rank.away}</td>
                        <td>
                            {notempty name="$rank.away_logo"}
                            <img src="{$rank.away_logo}" height="25">
                            {/notempty}
                        </td>
                        <td>
                            <a class="layui-btn layui-btn-xs layui-btn-danger del" data-id="{$rank.id}">删除</a>
                        </td>
                    </tr>
                    {/if}
                    {/volist}
                    <tr>
                        <th colspan="6" align="center">
                            1/4决赛
                        </th>
                    </tr>
                    <tr>
                        <th>主队</th>
                        <th>球队图标</th>
                        <th>客队</th>
                        <th>球队图标</th>
                        <th>设置</th>
                    </tr>
                    {volist name="match_rank" id="rank"}

                    {if $rank.rank_type == 2}
                    <tr>
                        <td>
                            {$rank.home}</td>
                        <td>
                            {notempty name="$rank.home_logo"}
                            <img src="{$rank.home_logo}" height="25">
                            {/notempty}

                        </td>
                        <td>
                            {$rank.away}</td>
                        <td>
                            {notempty name="$rank.away_logo"}
                            <img src="{$rank.away_logo}" height="25">
                            {/notempty}
                        </td>
                        <td>
                            <a class="layui-btn layui-btn-xs layui-btn-danger del" data-id="{$rank.id}">删除</a>
                        </td>
                    </tr>
                    {/if}
                    {/volist}
                    <tr>
                        <th colspan="6" align="center">
                            半决赛
                        </th>
                    </tr>
                    <tr>
                        <th>主队</th>
                        <th>球队图标</th>
                        <th>客队</th>
                        <th>球队图标</th>
                        <th>设置</th>
                    </tr>
                    {volist name="match_rank" id="rank"}
                    {if $rank.rank_type == 3}
                    <tr>
                        <td>
                            {$rank.home}</td>
                        <td>
                            {notempty name="$rank.home_logo"}
                            <img src="{$rank.home_logo}" height="25">
                            {/notempty}

                        </td>
                        <td>
                            {$rank.away}</td>
                        <td>
                            {notempty name="$rank.away_logo"}
                            <img src="{$rank.away_logo}" height="25">
                            {/notempty}
                        </td>
                        <td>
                            <a class="layui-btn layui-btn-xs layui-btn-danger del" data-id="{$rank.id}">删除</a>
                        </td>
                    </tr>
                    {/if}
                    {/volist}
                    <tr>
                        <th colspan="6" align="center">
                            决赛
                        </th>
                    </tr>
                    <tr>
                        <th>主队</th>
                        <th>球队图标</th>
                        <th>客队</th>
                        <th>球队图标</th>
                        <th>设置</th>
                    </tr>
                    {volist name="match_rank" id="rank"}

                    {if $rank.rank_type == 5}
                    <tr>
                        <td>
                            {$rank.home}</td>
                        <td>
                            {notempty name="$rank.home_logo"}
                            <img src="{$rank.home_logo}" height="25">
                            {/notempty}

                        </td>
                        <td>
                            {$rank.away}</td>
                        <td>
                            {notempty name="$rank.away_logo"}
                            <img src="{$rank.away_logo}" height="25">
                            {/notempty}
                        </td>
                        <td>
                            <a class="layui-btn layui-btn-xs layui-btn-danger del" data-id="{$rank.id}">删除</a>
                        </td>
                    </tr>
                    {/if}
                    {/volist}
                </table>
            </div>
        </div>
    </div>

    <script src="/layuiadmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '/layuiadmin/'
            , version: "{:config('other.ui_version')}"
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'worldcup', 'table', 'admin'], function () {
            var $ = layui.$
                , table = layui.table
                , admin = layui.admin


            $(".add-rank-match").on("click", function () {
                layer.open({
                    type: 2,
                    title: "添加积分",
                    content: "{:url('worldcup/rank_add')}",
                    maxmin: true,
                    area: ["650px", "500px"],
                });
            })

            // 重置淘汰
            $('#matchTable .del').click(function () {
                let id = $(this).data('id');
                layer.confirm('确定删除此条赛事吗？', function (index) {
                    layer.load();
                    $.ajax({
                        type: "POST",
                        url: "/admin/worldcup/rank_del",
                        dataType: "json",
                        data: { "id": id },
                        //请求成功
                        success: function (data) {
                            if (data.code == 0) {
                                layer.msg(data.msg, { icon: 1, time: 1200 }, function () {
                                    window.location.reload();
                                });
                            } else {
                                layer.msg(data.msg, { icon: 2 });
                            }
                        },
                        complete: function () {
                            layer.closeAll("loading");
                        },
                    });
                });
            })

            // 重置淘汰
            $('#matchTable .resetLose').click(function () {
                let match_id = $(this).parents('tr').eq(0).data('matchid');
                layer.confirm('确定重置淘汰设置吗？', function (index) {
                    layer.load();
                    $.ajax({
                        type: "POST",
                        url: "/admin/worldcup/reset_lose",
                        dataType: "json",
                        data: { "match_id": match_id },
                        //请求成功
                        success: function (data) {
                            if (data.code == 0) {
                                layer.msg(data.msg, { icon: 1, time: 1200 }, function () {
                                    window.location.reload();
                                });
                            } else {
                                layer.msg(data.msg, { icon: 2 });
                            }
                        },
                        complete: function () {
                            layer.closeAll("loading");
                        },
                    });
                });
            })

            // 设置淘汰
            $('#matchTable .setLose').click(function () {
                let match_id = $(this).parents('tr').eq(0).data('matchid');
                let lose_flag = $(this).data('loseflag');
                layer.confirm('确定设置该球队淘汰么？', function (index) {
                    layer.load();
                    $.ajax({
                        type: "POST",
                        url: "/admin/worldcup/rank_lose",
                        dataType: "json",
                        data: { "match_id": match_id, "lose_flag": lose_flag },
                        //请求成功
                        success: function (data) {
                            if (data.code == 0) {
                                layer.msg(data.msg, { icon: 1, time: 1200 }, function () {
                                    window.location.reload();
                                });
                            } else {
                                layer.msg(data.msg, { icon: 2 });
                            }
                        },
                        complete: function () {
                            layer.closeAll("loading");
                        },
                    });
                });
            })

            // 更新晋级图
            $('#matchTable .matchUpdate').click(function () {
                let match_id = $(this).parents('tr').eq(0).data('matchid');
                layer.confirm('确定要更新当前赛事吗？', function (index) {
                    layer.load();
                    $.ajax({
                        type: "POST",
                        url: "/admin/worldcup/rank_edit",
                        dataType: "json",
                        data: { "match_id": match_id },
                        //请求成功
                        success: function (data) {
                            if (data.code == 0) {
                                layer.msg(data.msg, { icon: 1, time: 1200 }, function () {
                                    window.location.reload();
                                });
                            } else {
                                layer.msg(data.msg, { icon: 2 });
                            }
                        },
                        complete: function () {
                            layer.closeAll("loading");
                        },
                    });
                });
            })

        });
    </script>
</body>

</html>